package com.help10000.rms.mvp.presenter

import com.amir.common.api.CustomObserver
import com.amir.common.beans.WorkOrderReportEntity
import com.amir.common.mvp.model.Model
import com.amir.common.mvp.presenter.BasePresenter
import com.amir.common.utils.Constant
import com.amir.common.utils.SPUtils
import com.help10000.rms.mvp.view.ManagerView
import java.text.SimpleDateFormat
import java.util.Calendar

class ManagerPresenter(view: ManagerView): BasePresenter<ManagerView>(view) {
    fun getData() {
        val token = SPUtils.getString(Constant.AccessToken)
        var dateFormat = SimpleDateFormat("yyyy-MM-dd")
        var tCal = Calendar.getInstance()
        tCal.add(Calendar.DATE, -1)
        var endDate = dateFormat.format(tCal.time)
        tCal.add(Calendar.DATE, -6)
        var startDate = dateFormat.format(tCal.time)

        val reportData = Model.getServer().workOrderReportR001(token, startDate, endDate)
        Model.getObservable(reportData,object : CustomObserver<WorkOrderReportEntity>(mvpView){
            override fun success(t: WorkOrderReportEntity) {
                mvpView?.SuccessData(t)
            }
        })
    }
}